package com.punch.order.controller;

import com.punch.order.constants.PayChannelEnum;
import com.punch.order.design.OrderContextFactory;
import com.punch.order.design.PayContext;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@Api(hidden = true)
public class PayNotifyController {


    @Resource
    private OrderContextFactory orderContextFactory;

    /**
     * 微信支付回调
     *
     * @param request  请求
     * @param response 响应
     */
    @PostMapping(value = "/notify/wx-pay")
//    @GlobalTransactional(rollbackFor = Exception.class)
    public String wxPayNotify(HttpServletRequest request, HttpServletResponse response) {
        PayContext orderSignContext = orderContextFactory.getContext(PayChannelEnum.WXPAY_APP.getCode());
        return orderSignContext.payNotify(request, response);
    }

    /**
     * 阿里支付回调
     *
     * @param request  请求
     * @param response 响应
     */
    @PostMapping(value = "/notify/al-pay")
//    @GlobalTransactional(rollbackFor = Exception.class)
    public String aliPayNotify(HttpServletRequest request, HttpServletResponse response) {
        PayContext orderSignContext = orderContextFactory.getContext(PayChannelEnum.ALIPAY_APP.getCode());
        return orderSignContext.payNotify(request, response);
    }
}
